﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace projetoFinal.pages.includes
{
    public partial class menuTop : System.Web.UI.UserControl
    {
        
        override protected void OnInit(EventArgs e)
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        public void setDiretorio(string nivel)
        {
            imgUser.Src = nivel + imgUser.Src;
            imgAdministracao.Src = nivel + imgAdministracao.Src;
            imgLogo.Src = nivel + imgLogo.Src;
            imgLogout.ImageUrl = nivel + imgLogout.ImageUrl;

            lnkAdministracao.HRef = nivel + lnkAdministracao.HRef;
            lnkAdministracaoImg.HRef = nivel + lnkAdministracaoImg.HRef;
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage("msg=1");
        }
        protected void imgLogout_Click(object sender, ImageClickEventArgs e)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage("msg=1");
        }
        
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                FormsIdentity identidade = (FormsIdentity)HttpContext.Current.User.Identity;
                if (identidade != null)
                {
                    FormsAuthenticationTicket ticket = identidade.Ticket;
                    lblUserName.Text = ticket.UserData;
                }
            }
        }
    }
}